.equ PERSON_SIZE,76
.section .data
	str1:
		.string "请输入名字>"
	str2:
		.string "%s"
	str3:
		.string "请输入年龄>"
	str4:
		.string "%d"
	str5:
		.string "请输入性别>"
	str6:
		.string "请输入电话>"
	str7:
		.string "请输入地址>"
	str8:
		.string "添加联系人成功\n"
.section .text
.global AddContact
.type AddContact,@function
AddContact:
	nop
	push %rbp
	mov %rsp,%rbp
	subq $24,%rsp
	movq %rdi,-8(%rbp) #接收结构体指针
#首先检查堆区内存是否需要扩容	
	mov -8(%rbp),%rdi
	#mov %rax,%rdi
	call CheckCapacity
	movq $str1,%rdi
	movq $0,%rax
	call printf
#获取用户输入写入内存
	mov -8(%rbp),%r8
	movl 12(%r8),%r9d #获取通讯录大小
	imull $PERSON_SIZE,%r9d
	movslq %r9d,%r9
	movq (%r8),%r10 #获取堆内存首地址
    leaq (%r10,%r9,1),%r12 #获取名字的偏移量 这里给一个被调用者保存寄存器
#调用scanf获取用户输入名字	
	mov $str2,%rdi
	mov %r12,%rsi
	call scanf
#获取用户输入年龄
	mov $str3,%rdi
	mov $0,%rax
	call printf
	
	mov $str4,%rdi
	leaq 20(%r12),%rsi
	call scanf
#获取用户输入性别
	mov $str5,%rdi
	mov $0,%rax
	call printf

	mov $str2,%rdi
	leaq 24(%r12),%rsi
	call scanf
#获取用户输入电话
	mov $str6,%rdi
	mov $0,%rax
	call printf

	mov $str2,%rdi
	leaq 34(%r12),%rsi
	call scanf
#获取用户输入地址
	mov $str7,%rdi
	mov $0,%rax
	call printf

	mov $str2,%rdi
	leaq 46(%r12),%rsi
	call scanf
#增加通讯录大小
	mov -8(%rbp),%r8
	incl 12(%r8)

	mov $0,%rax
	mov $str8,%rdi
	call printf
	
	leaveq 
	retq
